<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="com.javabean.*, java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
	<h1>圆的周长和面积计算</h1>
	 <%    
   
        Circle circle = null; 
	 	double r = 0;
        String radiusStr = request.getParameter("r"); 
        if (radiusStr != null && !radiusStr.isEmpty()) {  
            try {  
            	r = Double.parseDouble(radiusStr);
            	   circle = new Circle(r);  
            } catch (NumberFormatException e) {  
                r = 0;  
            }  
        }  
    %>
     <% if (circle != null) { %>
	<form action="circle.jsp" method="post">
		<table border="2px">
			<tr>
				<td>圆的半径：</td>
				<td><%=circle.getRadius() %></td>
			</tr>
			<tr>
					<td colspan="2" align="center"><input type="submit" value="计算"></td>
			</tr>
			<tr>
				<td>圆的面积：</td>
				<td><%=circle.getArea() %></td>
			</tr>
			<tr>
				<td>圆的周长：</td>
				<td><%=circle.getPerimeter() %></td>
			</tr>
		</table>
	</form>
	<%}else{ %>
	<form action="circle.jsp" method="post">
		<table border="2px">	<tr>
				<td>圆的半径：</td>
				<td><input type="text" name="r"></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="submit" value="计算"></td>
			</tr>
			<tr>
				<td>圆的面积：</td>
				<td></td>
			</tr>
			<tr>
				<td>圆的周长：</td>
				<td></td>
			</tr>
		</table>
	</form>
	<%} %>
</body>
</html>